/*     */ package com.newcrm.webapi.sub;
/*     */ 
/*     */ import com.newcrm.bean.CustomerInfo;
/*     */ import com.newcrm.bean.User;
/*     */ import com.newcrm.db.CustomerFieldManager;
/*     */ import com.newcrm.db.CustomerManager;
/*     */ import com.newcrm.db.DealFieldManager;
/*     */ import com.newcrm.db.UserManager;
/*     */ import com.newcrm.db.VOIPCallManager;
/*     */ import com.newcrm.exception.DBException;
/*     */ import com.newcrm.exception.NotFoundException;
/*     */ import com.newcrm.util.Util;
/*     */ import com.newcrm.webapi.AbstractHttpServlet;
/*     */ import java.io.IOException;
/*     */ import java.io.PrintWriter;
/*     */ import java.sql.SQLException;
/*     */ import java.util.Date;
/*     */ import java.util.List;
/*     */ import javax.servlet.RequestDispatcher;
/*     */ import javax.servlet.ServletException;
/*     */ import javax.servlet.http.HttpServletRequest;
/*     */ import javax.servlet.http.HttpServletResponse;
/*     */ import net.sf.json.JSONObject;
/*     */ import org.apache.log4j.Logger;
/*     */ 
/*     */ public class ShowPeople extends ShowCompany
/*     */ {
/*  34 */   private static Logger logger = Logger.getLogger(ShowPeople.class.getName());
/*     */ 
/*     */   public ShowPeople(AbstractHttpServlet servlet, String id) {
/*  37 */     super(servlet, id);
/*     */   }
/*     */ 
/*     */   public void parse(HttpServletRequest request, HttpServletResponse response)
/*     */     throws IOException, ServletException, NotFoundException
/*     */   {
/*  43 */     CustomerManager manager = new CustomerManager();
/*     */ 
/*  45 */     CustomerInfo customerInfo = null;
/*     */     try {
/*  47 */       customerInfo = manager.getCustomerInfo(this.id, true, true);
/*     */     } catch (Exception e) {
/*  49 */       throw new NotFoundException();
/*     */     }
/*  51 */     if (customerInfo == null) {
/*  52 */       throw new NotFoundException();
/*     */     }
/*     */ 
/*  55 */     User user = super.getLoginUser(request);
/*     */ 
/*  57 */     String ip = Util.getClientIpAddr(request);
/*  58 */     logger.warn("ip:" + ip + " / 用户Id：" + user.userId + " /  用户名：" + 
/*  59 */       user.name + ", 浏览了公司：id:  " + customerInfo.id + " / 名称：" + 
/*  60 */       customerInfo.name);
/*     */ 
/*  62 */     if (1 != customerInfo.type)
/*     */     {
/*  64 */       throw new NotFoundException();
/*     */     }
/*     */ 
/*  67 */     String type = Util.getURLParameter(request.getParameter("type"));
/*     */ 
/*  70 */     if (!customerInfo.hasViewRight(user, super.getCompany(user.companyId))) {
/*  71 */       if ("json".equals(type)) {
/*  72 */         showErrorMessage(response, "您没有查看该客户的权限");
/*  73 */         return;
/*     */       }
/*     */ 
/*  76 */       request.getRequestDispatcher("/nopermission.jsp").forward(
/*  77 */         request, response);
/*  78 */       return;
/*     */     }
/*     */ 
/*  82 */     UserManager userManager = new UserManager();
/*     */     try
/*     */     {
/*  85 */       userManager.addViewCustomerId(user.userId, 
/*  86 */         String.valueOf(customerInfo.id));
/*     */     } catch (DBException e) {
/*  88 */       logger.warn("add user view customer ids failed", e);
/*     */     } catch (SQLException e) {
/*  90 */       logger.warn("add user view customer ids failed", e);
/*     */     }
/*     */ 
/*  94 */     if ("json".equals(type)) {
/*  95 */       response.setContentType("text/html;charset=utf-8");
/*  96 */       PrintWriter out = response.getWriter();
/*  97 */       JSONObject jsonObject = new JSONObject();
/*  98 */       jsonObject.put("error", "0");
/*  99 */       jsonObject.put("customerInfo", customerInfo);
/* 100 */       out.println(jsonObject);
/* 101 */       out.flush();
/* 102 */       out.close();
/* 103 */       return;
/*     */     }
/*     */ 
/* 106 */     CustomerFieldManager manager2 = new CustomerFieldManager();
/*     */ 
/* 108 */     DealFieldManager dealFieldManager = new DealFieldManager();
/*     */ 
/* 110 */     List fields = manager2.list(user.companyId, 
/* 111 */       2);
/*     */     try
/*     */     {
/* 114 */       List dealFields = dealFieldManager
/* 115 */         .list(user.companyId);
/* 116 */       request.setAttribute("dealFields", dealFields);
/*     */     } catch (Exception e) {
/* 118 */       logger.warn("get people customer field info failed", e);
/*     */     }
/* 120 */     request.setAttribute("fields", fields);
/* 121 */     request.setAttribute("customerInfo", customerInfo);
/*     */ 
/* 124 */     VOIPCallManager voipCallManager = new VOIPCallManager();
/* 125 */     Date syncTime = voipCallManager.getLastSynchronousTime(user.companyId);
/* 126 */     request.setAttribute("syncTime", syncTime);
/*     */ 
/* 128 */     request.getRequestDispatcher("/people_detail.jsp").forward(request, 
/* 129 */       response);
/*     */   }
/*     */ }

/* Location:           C:\E\referenceProject\CRM参考\qikebao\WEB-INF\lib\qikebao.jar
 * Qualified Name:     com.newcrm.webapi.sub.ShowPeople
 * JD-Core Version:    0.6.1
 */